#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 1e5+10;
struct node
{
	int idx;
	int val;
}hh[maxn];
int flag[maxn];
char s[maxn][33];
bool cmp(node a,node b)
{
	if(a.val!=b.val) return a.val<b.val;
	else return a.idx<b.idx;
}
int main()
{
	int n;
	cin>>n;
	for(int i = 0;i<n;i++)
	{
		long long t = 0;
		cin>>s[i];
		int len = strlen(s[i]);
		for(int j = 0;j<len;j++)
		{
			long long m = (s[i][j]-'a')+1;
			t = t*26+m;
		}
		hh[i].idx = i;
		hh[i].val = t;
	}
	sort(hh,hh+n,cmp);
	memset(flag,0,sizeof(flag));
	for(int i = 1;i<n;i++)
	{
		if(hh[i].val==hh[i-1].val)
		{
			flag[hh[i].idx] = flag[hh[i-1].idx]+1;
		}
	}
	for(int i = 0;i<n;i++)
	{
		if(!flag[i]) puts("OK");
		else 
		{
			printf("%s%d\n",s[i],flag[i]);
		}
	}
} 
